package com.hp.bon.sgw.wh.processor;

import static com.hp.bon.sgw.Constants.LOG;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.hp.bon.sgw.Constants;
import com.hp.bon.sgw.bean.XmlMessage;
import com.hp.bon.sgw.core.CallParam;
import com.hp.bon.sgw.core.processor.Processor;
import com.hp.bon.sgw.util.Comutils;
import com.hp.bon.sgw.wh.service.SIDAndABMService;
import com.hp.bon.sgw.wh.util.DateUtil;

public class SIDAndAbmServiceProcessor extends Processor{
	private static final Logger logger = LoggerFactory.getLogger(SIDAndAbmServiceProcessor.class);
	private SIDAndABMService sidAndABMService;
	

	public SIDAndABMService getSidAndABMService() {
		return sidAndABMService;
	}

	public void setSidAndABMService(SIDAndABMService sidAndABMService) {
		this.sidAndABMService = sidAndABMService;
	}

	@Override
	public int process(CallParam callParam) {
		logger.info("===========start HBAndAbmServiceProcessor===============" );
		XmlMessage request = (XmlMessage) callParam.getRequest();
		try {
			String sig = request.getSIG();
		    String resp = callSIDAndABMService(callParam, request.getDATA(),StringUtils.isBlank(sig) ? 0 : Integer.valueOf(sig));
		    if(resp.equals("")) {
		    	callParam.setRetCode(1200);
		    	callParam.setResultMsg("time out");
		    	callParam.getAsynHandler().onCallResult(callParam);
		    }
		    else {
				LOG.warn("respStr------"+resp);
				XmlMessage ack = new XmlMessage(false);
				if(!resp.isEmpty()) {
					String resultCode="";
					String resultMsg="";
					try {
						resultCode=JSONObject.parseObject(resp).getString("resultCode");
						resultMsg=JSONObject.parseObject(resp).getString("resultMsg");
					} catch (Exception e) {

					}
					XmlMessage message = (XmlMessage)callParam.getRequest();
					String mid = message.getMID();
					Document docResp = Comutils.parseText(resp);
					ack.setDataElement(docResp.getRootElement());
					ack.setMID(mid.substring(0, mid.length()-1));
					ack.setREPTAG(0);
					ack.setRTT(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Long.valueOf(System.currentTimeMillis())));
					ack.setSIG(null);
					ack.setRC(resultCode);
					ack.setDS(resultMsg);
					ack.setDATA(resp);
					callParam.setRetCode(0);
					callParam.setServiceResultCode(0);
					callParam.setRecvResponse(ack);
				}
				callParam.getAsynHandler().onCallResult(callParam);
		    }
			
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		return 0;
	}
	
	private String callSIDAndABMService(CallParam callParam, String content,int sig) throws Exception {

		String resp = "";
		try {
			if("PublicAndAbm.NEW".equals(callParam.getCapability()) && sig != 0) {
				//通用型数据库直连
				switch (sig) {
				case 1:
					resp = callQryBalanceModifyLog(content);//帐本变更信息查询
					break;
				case 2:
					resp = callQryTax(content);//增值税查询
					break;
				case 3:
					resp = callBalance(content);//查询余额详情   查询余额列表
					break;
				case 4:
					resp = callBalanceType(content);//查询余额帐本类型详情   查询余额帐本类型列表
					break;
				case 5:
					resp = callPaymentMethod(content);//查询付款方式详情  查询付款方式列表
					break;
				case 6:
					resp = callAcctItemType(content);//查询帐目类型详情  查询帐目类型列表
					break;
				case 7:
					resp = callTaxItem(content);//查询税目详情 查询税目列表
					break;
				case 8:
					resp = callDepositType(content);//查询押金类型详情 查询押金类型列表
					break;
					
				default:
					break;
				}
			}
			
//			if("QryBalanceModifyLog.NEW".equals(callParam.getCapability())){
//				resp = callQryBalanceModifyLog(content);
//			}else if("QryTax.NEW".equals(callParam.getCapability())){
//				resp = callQryTax(content);
//			}else if("Balance.NEW".equals(callParam.getCapability())){
//				resp = callBalance(content);
//			}else if("BalanceType.NEW".equals(callParam.getCapability())){
//				resp = callBalanceType(content);
//			}else if("paymentMethod.NEW".equals(callParam.getCapability())){
//				resp = callPaymentMethod(content);
//			}else if("acctItemType.NEW".equals(callParam.getCapability())){
//				resp = callAcctItemType(content);
//			}else if("taxItem.NEW".equals(callParam.getCapability())){
//				resp = callTaxItem(content);
//			}else if("depositType.NEW".equals(callParam.getCapability())){
//				resp = callDepositType(content);
//			}
			logger.info("callSIDAndABMService end " + resp);
		} catch (Exception e) {
			logger.info("===========callHBAndABMService error ==============="+e.toString());
			throw e;
		}
		return resp;
	}
	
	/**
	 * 帐本变更信息查询
	 * @TODO
	 *
	 */
	private String callQryBalanceModifyLog(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			String beginDate = jsonContent.getString("beginDate");
			String endDate = jsonContent.getString("endDate");
			int objAttr = Integer.parseInt(jsonContent.getJSONObject("svcObjectStruct").getString("objAttr"));
			String objValue = jsonContent.getJSONObject("svcObjectStruct").getString("objValue");

			String queryAcctIdSql = "";
			String servDBName = "";
			String acc_nbr = "";
			String area_code = "";
			if (objAttr != 2) {
				if ("027".equals(objValue.substring(0, 2))) {
					servDBName = "ls65_sid";
					area_code = objValue.substring(0, 2);
					acc_nbr = objValue.substring(3);
				} else {
					servDBName = "ls65_sid2";
					area_code = objValue.substring(0, 3);
					acc_nbr = objValue.substring(4);
				}
				queryAcctIdSql = " select partition_id_region,serv_id,acct_id from " + servDBName
						+ ".serv_t where state='F0A' and serv_state!='F1R' and acc_nbr='" + acc_nbr + "' and area_code='"
						+ area_code + "' ";
			} else {
				acc_nbr = objValue;
				queryAcctIdSql = " select partition_id_region,serv_id,acct_id from ls65_sid.serv_t where state='F0A' and serv_state!='F1R' and acc_nbr='"
						+ acc_nbr + "' " + "union "
						+ "select partition_id_region,serv_id,acct_id from ls65_sid2.serv_t where state='F0A' and serv_state!='F1R' and acc_nbr='"
						+ acc_nbr + "' ";
			}
			List<Map<String,Object>> acctList = sidAndABMService.getSgwSIDList(queryAcctIdSql);
			Map<String, Object> data = new HashMap<String, Object>();
			if(acctList == null || acctList.isEmpty()) {
				data.put("resultCode", "501");
				data.put("resultMsg", "用户资料不存在");
				return new Gson().toJson(data);
			}
			// 封装返回信息
			
			if(acctList != null && !acctList.isEmpty()) {
				String acctID = String.valueOf(acctList.get(0).get("ACCT_ID"));
				String lantId = String.valueOf(acctList.get(0).get("PARTITION_ID_REGION"));
				String ABM_USER;
				String LATN_ABM;
				if("1001".equals(lantId)) {
					servDBName = "ls65_sid";
					LATN_ABM ="abm1_bal1";
				}else {
					servDBName = "ls65_sid2";
					LATN_ABM ="abm1_bal2";
				}
				List<Map<String, Object>> lantList = sidAndABMService.getLANT_AREA(lantId);
				ABM_USER = (String)lantList.get(0).get("BALANCE_LOG_USER");
				//LATN_ABM = (String)lantList.get(0).get("BALANCE_TYPE_USER");
				//Map<String, Object> lantMap = lantList.get(0);
				StringBuilder buildStringMes = new StringBuilder();
				LOG.warn("start webservice-----");
				//String ABM_USER = lantMap.get("BALANCE_LOG_USER").toString();
				List<String> MON_List = getMonthBetween(beginDate.substring(0,6),endDate.substring(0,6));
				List<Map<String,Object>> respTotalList = new ArrayList<Map<String,Object>>();
				for (String MON : MON_List) {
					buildStringMes.append("select a.oper_serial_nbr, a.balance_type_id ,b.balance_type_name,a.acct_id ,to_char(a.state_date,'yyyymmddhh24miss') state_date ,a.state,a.cycle_upper ,a.staff_id, a.site_id, to_char(a.state_date,'yyyymmddhh24miss')  from  ");
					buildStringMes.append(ABM_USER).append(".acct_balance_log_").append(MON).append("_T  a, ").append(LATN_ABM).append(".acct_balance_Type_t b ");
					buildStringMes.append(" where  a.state_date between to_date(").append(beginDate).append(",'yyyymmddhh24miss') ");
					buildStringMes.append(" and to_date(").append(endDate).append(",'yyyymmddhh24miss') ");
					buildStringMes.append(" and acct_id = '").append(acctID).append("' and a.balance_type_id = b.balance_type_id ");
					LOG.warn("dealQryBalanceModifyLog buildStringMes------" + buildStringMes.toString());
					List<Map<String,Object>> respList = sidAndABMService.getSgwABMList(buildStringMes.toString());
					//{"STATE_DATE":"Jun 1, 2019","SITE_ID":0,"BALANCE_TYPE_NAME":"普通存款"}
					for (Map<String, Object> map : respList) {
						data.put("serviceId", map.get("OPER_SERIAL_NBR"));
						data.put("balanceTypeId", map.get("BALANCE_TYPE_ID"));
						data.put("balanceTypeName", map.get("BALANCE_TYPE_NAME"));
						data.put("acctId", map.get("ACCT_ID"));
						data.put("date", map.get("STATE_DATE"));
						data.put("sdate", map.get("STATE"));
						data.put("topLimit", map.get("CYCLE_UPPER"));
						data.put("staffId", map.get("STAFF_ID"));
						data.put("orgId", map.get("SITE_ID"));
						data.put("modifyDate", map.get("STATE_DATE"));
					}
					respTotalList.addAll(respList);
					buildStringMes=new StringBuilder();
				}
				LOG.info("respTotalList :"+new Gson().toJson(respTotalList));
			}
			data.put("resultCode", "0");
			data.put("resultMsg", "SUCCESS");
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		return resp;
	}
	
	
	/**
	 * 增值税查询
	 * @TODO
	 *
	 */
	private String callQryTax(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			int objAttr = Integer.parseInt(jsonContent.getJSONObject("svcObjectStruct").getString("objAttr"));
			String objValue = jsonContent.getJSONObject("svcObjectStruct").getString("objValue");
			String queryServIdSql = "";
			String servDBName = "";
			String acc_nbr = "";
			String area_code = "";
			if (objAttr != 2) {
				if ("027".equals(objValue.substring(0, 2))) {
					servDBName = "ls65_sid";
					area_code = objValue.substring(0, 2);
					acc_nbr = objValue.substring(3);
				} else {
					servDBName = "ls65_sid2";
					area_code = objValue.substring(0, 3);
					acc_nbr = objValue.substring(4);
				}
				queryServIdSql = " select partition_id_region,serv_id from " + servDBName + ".serv_t where state='F0A' and serv_state!='F1R' and acc_nbr='"
						+ acc_nbr + "' and area_code='" + area_code + "'";
			} else {
				acc_nbr = objValue;
				queryServIdSql = " select partition_id_region,serv_id from ls65_sid.serv_t where state='F0A' and serv_state!='F1R' and acc_nbr='"
						+ acc_nbr + "' " + "union "
						+ "select partition_id_region,serv_id from ls65_sid2.serv_t where state='F0A' and serv_state!='F1R' and acc_nbr='" + acc_nbr + "' ";
			}
			List<Map<String,Object>> acctList = sidAndABMService.getSgwSIDList(queryServIdSql);
			Map<String, Object> data = new HashMap<String, Object>();
			String BILLINGCYCLE_ID = jsonContent.getString("billingCycleId");
			if(acctList == null || acctList.isEmpty()) {
				data.put("resultCode", "501");
				data.put("resultMsg", "用户资料不存在");
				return new Gson().toJson(data);
			}
			// 封装返回信息
			
			String servID = String.valueOf(acctList.get(0).get("SERV_ID"));
			String lantId = String.valueOf(acctList.get(0).get("PARTITION_ID_REGION"));
			if("1001".equals(lantId ) ) {
				servDBName = "ls65_sid";
			}else {
				servDBName = "ls65_sid2";
			}
			List<Map<String, Object>> lantList = sidAndABMService.getLANT_AREA(lantId);
			String QTBZ_USER = (String)lantList.get(0).get("QTBZ_USER");
			
			String SID_FLAG = servDBName;
			String buildStringMes = "select a.acct_month, "
									+ "a.acct_item_type_id, "
									+ "d.name, "
									+ "c.tax_item_id, "
									+ "c.tax_calc_name, "
									+ "c.tax_rate, "
									+ "a.tax_amount, "
									+ "(a.amount - a.tax_amount) aftertaxcharge "
									+ "from " + QTBZ_USER + ".bill_tax_detail_" + BILLINGCYCLE_ID + "_t a, "
									+ SID_FLAG + ".tax_calculate_t c,"
									+ SID_FLAG + ".acct_item_type_t d "
									+ "where a.acct_item_type_id = d.acct_item_type_id and a.tax_calc_id = c.tax_calc_id and a.serv_id='" + servID + "'";
			
			List<Map<String,Object>> respList = sidAndABMService.getSgwABMList(buildStringMes);
			List<Map<String, Object>> taxInfoList = new ArrayList<Map<String, Object>>();
			for(Map<String, Object> map : respList){
				Map<String, Object> m = new HashMap<String, Object>();
				m.put("accNbr", acc_nbr);
				m.put("acctItemTypeId", map.get("ACCT_ITEM_TYPE_ID"));
				m.put("acctItemTypeName", map.get("NAME"));
				m.put("taxItemId", map.get("TAX_ITEM_ID"));
				m.put("taxItemIdName", map.get("TAX_CALC_NAME"));
				m.put("taxRate", map.get("TAX_RATE"));
				m.put("taxCharge", map.get("TAX_AMOUNT"));
				m.put("afterTaxCharge", map.get("AFTERTAXCHARGE"));
				taxInfoList.add(m);
			}
			data.put("billingCycleId", BILLINGCYCLE_ID);
			data.put("taxInfoList", taxInfoList);
			
			data.put("resultCode", "0");
			data.put("resultMsg", "SUCCESS");
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		
		return resp;
	}
	/**
	 * 查询余额详情  /balance/{acctBalanceId}
	 * 查询余额列表 /balance
	 * @TODO
	 *
	 */
	private String callBalance(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			if(jsonContent == null) {
				jsonContent= new JSONObject();
			}
			String queryServIdSql="";
			int isbalance=jsonContent.getString("isOne") == null ? 1 : 0;//0标记为查询余额详情
			String acctBalanceId = jsonContent.getString("acctBalanceId");
			String lantId="";
			String ABM_USER="";
			StringBuffer sqltemp=new StringBuffer();
			if( isbalance == 0) {
				//查询余额详情
				lantId=acctBalanceId.substring(0,4);
				sqltemp.append(" and acct_balance_id = substr('"+acctBalanceId+"', 5)");
			}else {
				//查询余额列表
				
				if(StringUtils.isNotBlank(acctBalanceId)) {
					lantId=acctBalanceId.substring(0,4);
					sqltemp.append(" and acct_balance_id = substr('"+acctBalanceId+"', 5)");
				}else {
					String acctId = jsonContent.getString("acctId");
					lantId=acctId.substring(0,4);
					sqltemp.append(" and acct_id = substr('"+acctId+"', 5)");
				}
				
				if(StringUtils.isNotBlank(jsonContent.getString("balanceTypeId"))) {
					sqltemp.append(" and balance_type_id = '"+jsonContent.getString("balanceTypeId")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("balance"))) {
					sqltemp.append(" and balance = '"+jsonContent.getString("balance")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("reserveBalance"))) {
					sqltemp.append(" and reserve_balance  = '"+jsonContent.getString("reserveBalance")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("cycleType"))) {
					sqltemp.append(" and quota_type  = '"+jsonContent.getString("cycleType")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("cycleUpper"))) {
					sqltemp.append(" and  cycle_upper = '"+jsonContent.getString("cycleUpper")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("cycleLower"))) {
					sqltemp.append(" and  cycle_lower = '"+jsonContent.getString("cycleLower")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("shareRuleFlag"))) {
					sqltemp.append(" and use_rule_flag  = '"+jsonContent.getString("shareRuleFlag")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("effDate"))) {
					sqltemp.append(" and  eff_date = '"+jsonContent.getString("effDate")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("expDate"))) {
					sqltemp.append(" and exp_date  = '"+jsonContent.getString("expDate")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("statusCd"))) {
					sqltemp.append(" and  state = '"+jsonContent.getString("statusCd")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("statusDate"))) {
					sqltemp.append(" and  state_date	 = '"+jsonContent.getString("statusDate")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("createDate"))) {
					sqltemp.append(" and  create_date = '"+jsonContent.getString("createDate")+"'");
				}
				
			}
			List<Map<String, Object>> lantList = sidAndABMService.getLANT_AREA(lantId);
			ABM_USER= (String)lantList.get(0).get("BALANCE_LOG_USER");
			queryServIdSql="select  acct_balance_id ,balance_type_id,balance,acct_id,reserve_balance,quota_type,cycle_upper,cycle_lower,use_rule_flag,to_char(eff_date,'yyyymmddhh24miss') eff_date,to_char(exp_date,'yyyymmddhh24miss') exp_date,state,to_char(state_date,'yyyymmddhh24miss') state_date,to_char(create_date,'yyyymmddhh24miss') create_date   from   "+ABM_USER+".acct_balance_t\r\n" + 
					"WHERE 1=1 "+sqltemp.toString();
			
			List<Map<String,Object>> resulttList = sidAndABMService.getSgwABMList(queryServIdSql);
			
			// 封装返回信息
			Map<String, Object> data = new HashMap<String, Object>();
			if(resulttList != null && !resulttList.isEmpty()) {
				List<Map<String, Object>> balanceList = new ArrayList<Map<String, Object>>();
				for(Map<String, Object> map : resulttList){
					Map<String, Object> m = new HashMap<String, Object>();
					m.put("acctBalanceId", map.get("ACCT_BALANCE_ID"));
					m.put("balanceTypeId", map.get("BALANCE_TYPE_ID"));
					m.put("balance", map.get("BALANCE"));
					m.put("acctId", map.get("ACCT_ID"));
					m.put("reserveBalance", map.get("RESERVE_BALANCE"));
					m.put("cycleType", map.get("QUOTA_TYPE"));
					m.put("cycleUpper", map.get("CYCLE_UPPER"));
					m.put("cycleLower", map.get("CYCLE_LOWER"));
					m.put("shareRuleFlag", map.get("USE_RULE_FLAG"));
					m.put("effDate", map.get("EFF_DATE"));
					m.put("expDate", map.get("EXP_DATE"));
					m.put("statusCd", map.get("STATE"));
					m.put("statusDate", map.get("STATE_DATE"));
					m.put("createDate", map.get("CREATE_DATE"));
					m.put("remark", map.get(""));
					balanceList.add(m);
				}
				if(isbalance == 0) {
					//单条
					data.put("balance", balanceList.get(0));
					data.put("Id", "");
					data.put("href", "");
				}else {
					//列表
					data.put("balance", balanceList);
				}
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else if(resulttList != null){
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else {
				data.put("resultCode", "-1");
				data.put("resultMsg", "查询失败");
			}
			
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		return resp;
	}
	
	
	/**
	 * 查询余额帐本类型详情  /balanceType/{balanceTypeId}
	 * 查询余额帐本类型列表  /balanceType
	 * @TODO
	 *
	 */
	private String callBalanceType(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			if(jsonContent == null) {
				jsonContent= new JSONObject();
			}
			String queryServIdSql="";
			int isbalance=0;//查询余额帐本类型列表
			String balanceTypeId = jsonContent.getString("balanceTypeId");
			StringBuffer sqltemp=new StringBuffer();
			if( StringUtils.isNotBlank(balanceTypeId)  && jsonContent.size() == 1) {
				//查询余额帐本类型详情
				isbalance=1;
				sqltemp.append(" and balance_type_id = "+balanceTypeId);
			}else {
				//查询余额帐本类型列表
				if(StringUtils.isNotBlank(balanceTypeId)) {
					sqltemp.append(" and balance_type_id = '"+balanceTypeId+"'");
				}
				
				if(StringUtils.isNotBlank(jsonContent.getString("priority"))) {
					sqltemp.append(" and seq_id = '"+jsonContent.getString("priority")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("spePaymentId"))) {
					sqltemp.append(" and substr(balance_use_limits, 7,1 ) = '"+jsonContent.getString("spePaymentId")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("measureMethodId"))) {
					sqltemp.append(" and measure_method_id  = '"+jsonContent.getString("measureMethodId")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("balanceTypeName"))) {
					sqltemp.append(" and  balance_type_name  = '"+jsonContent.getString("balanceTypeName")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("allowDraw"))) {
					sqltemp.append(" and  substr(balance_use_limits, 1,1 ) = '"+jsonContent.getString("allowDraw")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("invOffer"))) {
					sqltemp.append(" and  substr(balance_use_limits, 3,1 ) = '"+jsonContent.getString("invOffer")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("ifEarning"))) {
					sqltemp.append(" and substr(balance_use_limits, 11,1 )  = '"+jsonContent.getString("ifEarning")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("ifPayold"))) {
					sqltemp.append(" and  substr(balance_use_limits, 8,1 ) = '"+jsonContent.getString("ifPayold")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("ifSaveback"))) {
					sqltemp.append(" and substr(balance_use_limits, 17,1 )  = '"+jsonContent.getString("ifSaveback")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("ifPrincipal"))) {
					sqltemp.append(" and  substr(balance_use_limits, 11,1 ) = '"+jsonContent.getString("ifPrincipal")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("operFlag"))) {
					sqltemp.append(" and  substr(balance_use_limits, 16,1 )	 = '"+jsonContent.getString("operFlag")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("transFlag"))) {
					sqltemp.append(" and  substr(balance_use_limits, 12,1 )  = '"+jsonContent.getString("transFlag")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("regionId"))) {
					sqltemp.append(" and   region_id = "+jsonContent.getString("regionId"));
				}
			}
			String sql1=" select  balance_type_id,\r\n" + 
					"seq_id,\r\n" + 
					"substr(balance_use_limits, 7,1 ),\r\n" + 
					"measure_method_id,\r\n" + 
					" balance_type_name,\r\n" + 
					"substr(balance_use_limits, 1,1 ),\r\n" + 
					"substr(balance_use_limits, 3,1 ),\r\n" + 
					"substr(balance_use_limits, 11,1 ),\r\n" + 
					"substr(balance_use_limits, 8,1 ),\r\n" + 
					"substr(balance_use_limits, 17,1 ),\r\n" + 
					"substr(balance_use_limits, 11,1 ),\r\n" + 
					"substr(balance_use_limits, 16,1 ),\r\n" + 
					"substr(balance_use_limits, 12,1 ),\r\n" + 
					"region_id,eff_date,exp_date\r\n" + 
					"   from  ";
			queryServIdSql=sql1+" abm1_bal1.acct_balance_type_t \r\n" + 
					"where  1=1 " + sqltemp.toString()+
					" union all "+sql1+"abm1_bal2.acct_balance_type_t \r\n" + 
					" where 1=1 " + sqltemp.toString();
			
			List<Map<String,Object>> resulttList = sidAndABMService.getSgwABMList(queryServIdSql);
			//[{SUBSTR(BALANCE_USE_LIMITS,16,1)=1, =0, =1, =2008-04-20, =UVC充值卡, =0, =0, =2, =1001, =2038-12-31, =0, =10050, =400, =0, =0}, {SUBSTR(BALANCE_USE_LIMITS,16,1)=1, SUBSTR(BALANCE_USE_LIMITS,12,1)=0, SUBSTR(BALANCE_USE_LIMITS,1,1)=1, EFF_DATE=2008-04-20, BALANCE_TYPE_NAME=UVC充值卡, SUBSTR(BALANCE_USE_LIMITS,11,1)=0, SUBSTR(BALANCE_USE_LIMITS,7,1)=0, MEASURE_METHOD_ID=2, REGION_ID=1001, EXP_DATE=2038-12-31, SUBSTR(BALANCE_USE_LIMITS,8,1)=0, BALANCE_TYPE_ID=10050, SEQ_ID=400, SUBSTR(BALANCE_USE_LIMITS,3,1)=0, SUBSTR(BALANCE_USE_LIMITS,17,1)=0}]
			// 封装返回信息
			Map<String, Object> data = new HashMap<String, Object>();
			if(resulttList != null && !resulttList.isEmpty()) {
				List<Map<String, Object>> balanceList = new ArrayList<Map<String, Object>>();
				for(Map<String, Object> map : resulttList){
					Map<String, Object> m = new HashMap<String, Object>();
					m.put("balanceTypeId", map.get("BALANCE_TYPE_ID"));
					m.put("priority", map.get("SEQ_ID"));
					m.put("spePaymentId", map.get("SUBSTR(BALANCE_USE_LIMITS,7,1)"));
					m.put("measureMethodId", map.get("MEASURE_METHOD_ID"));
					m.put("balanceTypeName", map.get("BALANCE_TYPE_NAME"));
					m.put("allowDraw", map.get("SUBSTR(BALANCE_USE_LIMITS,1,1)"));
					m.put("invOffer", map.get("SUBSTR(BALANCE_USE_LIMITS,3,1)"));
					m.put("ifEarning", map.get("SUBSTR(BALANCE_USE_LIMITS,11,1)"));
					m.put("ifPayold", map.get("SUBSTR(BALANCE_USE_LIMITS,8,1)"));
					m.put("ifSaveback", map.get("SUBSTR(BALANCE_USE_LIMITS,17,1)"));
					m.put("ifPrincipal", map.get("SUBSTR(BALANCE_USE_LIMITS,11,1)"));
					m.put("operFlag", map.get("SUBSTR(BALANCE_USE_LIMITS,16,1)"));
					m.put("transFlag", map.get("SUBSTR(BALANCE_USE_LIMITS,12,1)"));
					m.put("regionId", map.get("REGION_ID"));
					m.put("statusCd", map.get(""));
					m.put("createStaff", map.get(""));
					m.put("updateStaff", map.get(""));
					m.put("createDate", map.get("EFF_DATE"));
					m.put("statusDate", map.get("EFF_DATE"));
					m.put("updateDate", map.get("EFF_DATE"));
					//EXP_DATE
					balanceList.add(m);
				}
				if(isbalance == 1) {
					//单条
					data.put("balanceType", balanceList.get(0));
					data.put("Id", "");
					data.put("href", "");
				}else {
					//列表
					data.put("balanceType", balanceList);
				}
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
				
			}else if(resulttList != null){
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else {
				data.put("resultCode", "-1");
				data.put("resultMsg", "查询失败");
			}
			
			
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		return resp;
	}
	
	/**
	 * 查询付款方式详情 
	 * 查询付款方式列表
	 * (无网段)
	 * paymentMethod
	 * @TODO
	 *
	 */
	private String callPaymentMethod(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			if(jsonContent == null) {
				jsonContent= new JSONObject();
			}
			String queryServIdSql="";
			int isbalance=jsonContent.getString("isOne") == null ? 1 : 0;//0标记为查询详情
			String paymentMethod = jsonContent.getString("paymentMethod");
			StringBuffer sqltemp=new StringBuffer();
			if( isbalance == 0) {
				//查询详情
				queryServIdSql = "select a.code_flag, a.code_name, a.state\r\n" + 
						"  from ls65_sid2.code_name_t a\r\n" + 
						" where code_type = 'CASHPAY_STATE'\r\n" + 
						"and code_flag= "+paymentMethod+" \r\n" + 
						"union \r\n" + 
						"select a.code_flag, a.code_name, a.state\r\n" + 
						"  from ls65_sid.code_name_t a\r\n" + 
						" where code_type = 'CASHPAY_STATE'\r\n" + 
						"and code_flag="+paymentMethod;
			}else {
				//查询列表
				if(StringUtils.isNotBlank(paymentMethod)) {
					sqltemp.append(" and code_flag = '"+paymentMethod +"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("paymentMethodName"))) {
					sqltemp.append(" and code_name  = '"+jsonContent.getString("paymentMethodName")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("statusCd"))) {
					sqltemp.append(" and state = '"+jsonContent.getString("statusCd")+"'");
				}
				queryServIdSql="select a.code_flag, a.code_name, a.state\r\n" + 
						"  from ls65_sid2.code_name_t a\r\n" + 
						" where code_type = 'CASHPAY_STATE' " +  sqltemp.toString();
			}
			
			
			List<Map<String,Object>> resulttList = sidAndABMService.getSgwABMList(queryServIdSql);
			
			// 封装返回信息
			Map<String, Object> data = new HashMap<String, Object>();
			if(resulttList != null && !resulttList.isEmpty()) {
				List<Map<String, Object>> balanceList = new ArrayList<Map<String, Object>>();
				for(Map<String, Object> map : resulttList){
					Map<String, Object> m = new HashMap<String, Object>();
					m.put("paymentMethod", map.get("CODE_FLAG"));
					m.put("paymentMethodName", map.get("CODE_NAME"));
					m.put("statusCd", map.get("STATE"));
					m.put("createStaff", "");
					m.put("updateStaff", "");
					m.put("createDate", "");
					m.put("updateDate", "");
					m.put("statusDate", "");
					balanceList.add(m);
				}
				if(isbalance == 0) {
					//单条
					data.put("paymentMethod", balanceList.get(0));
				}else {
					//列表
					data.put("paymentMethod", balanceList);
				}
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else if(resulttList != null){
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else {
				data.put("resultCode", "-1");
				data.put("resultMsg", "查询失败");
			}
			
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		return resp;
	}
	
	/**
	 * 查询帐目类型详情
	 * 查询帐目类型列表
	 * acctItemType
	 * 无网段
	 * @TODO
	 *
	 */
	private String callAcctItemType(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			if(jsonContent == null) {
				jsonContent= new JSONObject();
			}
			String queryServIdSql="";
			int isbalance=jsonContent.getString("isOne") == null ? 1 : 0;//0标记为查询详情
			String acctItemTypeId = jsonContent.getString("acctItemTypeId");
			StringBuffer sqltemp=new StringBuffer();
			if( isbalance == 0) {
				//查询详情
				queryServIdSql = "select acct_item_type_id,acct_item_class_id,party_role_id,name,charge_mark,total_mark,acct_item_type_code,seq_id\r\n" + 
						"from  ls65_sid.acct_item_type_t where acct_item_type_id ="+acctItemTypeId+"\r\n" + 
						"union\r\n" + 
						"select acct_item_type_id,acct_item_class_id,party_role_id,name,charge_mark,total_mark,acct_item_type_code,seq_id\r\n" + 
						"from  ls65_sid2.acct_item_type_t where acct_item_type_id ="+acctItemTypeId;
			}else {
				//查询列表
				if(StringUtils.isNotBlank(acctItemTypeId)) {
					sqltemp.append(" and acct_item_type_id = '"+acctItemTypeId +"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("partnerId"))) {
					sqltemp.append(" and party_role_id  = '"+jsonContent.getString("partnerId")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("name"))) {
					sqltemp.append(" and name = '"+jsonContent.getString("name")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("chargeMark"))) {
					sqltemp.append(" and charge_mark = '"+jsonContent.getString("chargeMark")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("totalMark"))) {
					sqltemp.append(" and total_mark = '"+jsonContent.getString("totalMark")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("acctItemTypeCod"))) {
					sqltemp.append(" and acct_item_type_code = '"+jsonContent.getString("acctItemTypeCod")+"'");
				}
				
				queryServIdSql="select acct_item_type_id,acct_item_class_id,party_role_id,name,charge_mark,total_mark,acct_item_type_code,seq_id\r\n" + 
						"from  ls65_sid.acct_item_type_t where 1=1 "+sqltemp.toString() +" union select acct_item_type_id,acct_item_class_id,party_role_id,name,charge_mark,total_mark,acct_item_type_code,seq_id\r\n" + 
								"from  ls65_sid2.acct_item_type_t where 1=1 "+sqltemp.toString();
			}
			
			
			List<Map<String,Object>> resulttList = sidAndABMService.getSgwABMList(queryServIdSql);

			// 封装返回信息
			Map<String, Object> data = new HashMap<String, Object>();
			if(resulttList != null && !resulttList.isEmpty()) {
				List<Map<String, Object>> balanceList = new ArrayList<Map<String, Object>>();
				for(Map<String, Object> map : resulttList){
					Map<String, Object> m = new HashMap<String, Object>();
					m.put("acctItemTypeId", map.get("ACCT_ITEM_TYPE_ID"));
					m.put("acctItemClassId", map.get("ACCT_ITEM_CLASS_ID"));
					m.put("partnerId", map.get("PARTY_ROLE_ID"));
					m.put("name", map.get("NAME"));
					m.put("chargeMark", map.get("CHARGE_MARK"));
					m.put("totalMark", map.get("TOTAL_MARK"));
					m.put("acctItemTypeCod", map.get("ACCT_ITEM_TYPE_CODE"));
					m.put("priority", map.get("SEQ_ID"));
					m.put("parentItemTypeId", "");
					m.put("ifAdjust", "");
					m.put("statusCd", "");
					m.put("createStaff", "");
					m.put("updateStaff", "");
					m.put("statusDate", "");
					balanceList.add(m);
				}
				if(isbalance == 0) {
					//单条
					data.put("acctItemType", balanceList.get(0));
				}else {
					//列表
					data.put("acctItemType", balanceList);
				}
				
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else if(resulttList != null){
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else {
				data.put("resultCode", "-1");
				data.put("resultMsg", "查询失败");
			}
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		return resp;
	}
	
	/**
	 * 查询税目详情
	 * 查询税目列表
	 * taxItem
	 * @TODO
	 *
	 */
	private String callTaxItem(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			if(jsonContent == null) {
				jsonContent= new JSONObject();
			}
			String queryServIdSql="";
			int isbalance=jsonContent.getString("isOne") == null ? 1 : 0;//0标记为查询详情
			String taxItemId = jsonContent.getString("taxItemId");
			StringBuffer sqltemp=new StringBuffer();
			if( isbalance == 0) {
				//查询详情
				queryServIdSql = "select tax_calc_id,tax_calc_name,scenario_id,check_expr,tax_id,tax_item_id,precision,rounding_rule,calc_order,inclusive_flag,region_id,tax_rate,eff_date,exp_date\r\n" + 
						"from  ls65_sid2.tax_calculate_t where tax_calc_id="+taxItemId+"\r\n" + 
						"union \r\n" + 
						"select tax_calc_id,tax_calc_name,scenario_id,check_expr,tax_id,tax_item_id,precision,rounding_rule,calc_order,inclusive_flag,region_id,tax_rate,eff_date,exp_date\r\n" + 
						"from  ls65_sid.tax_calculate_t where tax_calc_id="+taxItemId;
			}else {
				//查询列表
				
				if(StringUtils.isNotBlank(taxItemId)) {
					sqltemp.append(" and tax_calc_id = '"+taxItemId +"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("taxItemName"))) {
					sqltemp.append(" and tax_calc_name  = '"+jsonContent.getString("taxItemName")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("taxItemCode"))) {
					sqltemp.append(" and tax_item_id  = '"+jsonContent.getString("taxItemCode")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("taxRate"))) {
					sqltemp.append(" and tax_rate = '"+jsonContent.getString("taxRate")+"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("statusCd"))) {
					sqltemp.append(" and inclusive_flag = '"+jsonContent.getString("statusCd")+"'");
				}
				String regionId = jsonContent.getString("regionId");//区域标识
				String sql1=" select tax_calc_id,tax_calc_name,scenario_id,check_expr,tax_id,tax_item_id,precision,rounding_rule,calc_order,inclusive_flag,region_id,tax_rate,eff_date,exp_date\r\n" + 
						"from  ls65_sid.tax_calculate_t where 1=1 ";
				String sql2=" select tax_calc_id,tax_calc_name,scenario_id,check_expr,tax_id,tax_item_id,precision,rounding_rule,calc_order,inclusive_flag,region_id,tax_rate,eff_date,exp_date\r\n" + 
						"from  ls65_sid2.tax_calculate_t where 1=1 ";
				if(StringUtils.isBlank(regionId)) {
					//如果regionId不存在值，then 查询ls65_sid和ls65_sid2这两个库下面的表同时查
					queryServIdSql = sql1 + sqltemp.toString() + " union " + sql2  + sqltemp.toString();
					
				}else if("1001".equals(regionId)) {
					//如果regionId=1001 then 查询ls65_sid. tax_calculate_t
					queryServIdSql = sql1 + sqltemp.toString();
					
				}else {
					//如果regionId！=1001 then ls65_sid2. tax_calculate_t
					queryServIdSql = sql2 + sqltemp.toString();
					
				}
			}
			
			
			List<Map<String,Object>> resulttList = sidAndABMService.getSgwABMList(queryServIdSql);
			//TAX_CALC_ID  TAX_CALC_NAME   TAX_ITEM_ID  TAX_RATE   REGION_ID  REMARKS INCLUSIVE_FLAG   

			// 封装返回信息
			Map<String, Object> data = new HashMap<String, Object>();
			if(resulttList != null && !resulttList.isEmpty()) {
				List<Map<String, Object>> balanceList = new ArrayList<Map<String, Object>>();
				for(Map<String, Object> map : resulttList){
					Map<String, Object> m = new HashMap<String, Object>();
					m.put("taxItemId", map.get("TAX_CALC_ID"));
					m.put("taxItemName", map.get("TAX_CALC_NAME"));
					m.put("taxItemCode", map.get("TAX_ITEM_ID"));
					m.put("taxRate", map.get("TAX_RATE"));
					m.put("regoinId", map.get("REGION_ID"));
					m.put("remark", map.get("REMARKS"));
					m.put("statusCd", map.get("INCLUSIVE_FLAG"));
					m.put("createStaff", "");
					m.put("updateStaff", "");
					m.put("createDate", "");
					m.put("updateDate", "");
					m.put("statusDate", "");
					balanceList.add(m);
				}
				if(isbalance == 0) {
					//单条
					data.put("taxItem", balanceList.get(0));
				}else {
					//列表
					data.put("taxItem", balanceList);
				}
				
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else if(resulttList != null){
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else {
				data.put("resultCode", "-1");
				data.put("resultMsg", "查询失败");
			}
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		return resp;
	}
	
	/**
	 * 查询押金类型详情
	 * 查询押金类型列表
	 * depositType
	 * @TODO
	 *
	 */
	private String callDepositType(String content) throws Exception  {
		String resp = "";
		try {
			JSONObject jsonContent = JSON.parseObject(content);
			if(jsonContent == null) {
				jsonContent= new JSONObject();
			}
			String queryServIdSql="";
			int isbalance=jsonContent.getString("isOne") == null ? 1 : 0;//0标记为查询详情
			String depositTypeId = jsonContent.getString("depositTypeId");
			StringBuffer sqltemp=new StringBuffer();
			if( isbalance == 0) {
				//查询详情
				queryServIdSql = "select   balance_type_id,balance_type_name,region_id, eff_date\r\n" + 
						"   from    abm1_bal1. acct_balance_type_t  where  balance_type_name like '%押金%' and balance_type_id="+depositTypeId+"\r\n" + 
						"union \r\n" + 
						"select   balance_type_id,balance_type_name,region_id, eff_date\r\n" + 
						"   from    abm1_bal2. acct_balance_type_t  where  balance_type_name like '%押金%' and balance_type_id="+depositTypeId;
			}else {
				//查询列表
				
				if(StringUtils.isNotBlank(depositTypeId)) {
					sqltemp.append(" and balance_type_id = '"+depositTypeId +"'");
				}
				if(StringUtils.isNotBlank(jsonContent.getString("depositTypeName"))) {
					sqltemp.append(" and balance_type_name  = '"+jsonContent.getString("depositTypeName ")+"'");
				}
				String regionId = jsonContent.getString("regionId");//区域标识
				String sql1=" select   balance_type_id,balance_type_name,region_id, eff_date\r\n" + 
						"   from    abm1_bal1.acct_balance_type_t  where  balance_type_name like '%押金%' ";
				String sql2=" select   balance_type_id,balance_type_name,region_id, eff_date\r\n" + 
						"   from    abm1_bal2.acct_balance_type_t  where  balance_type_name like '%押金%' ";
				if(StringUtils.isBlank(regionId)) {
					//如果regionId不存在值，then 查询ls65_sid和ls65_sid2这两个库下面的表同时查
					queryServIdSql = sql1 + sqltemp.toString() + " union " + sql2  + sqltemp.toString();
					
				}else if("1001".equals(regionId)) {
					//如果regionId=1001 then 查询ls65_sid. tax_calculate_t
					queryServIdSql = sql1 + sqltemp.toString();
					
				}else {
					//如果regionId！=1001 then ls65_sid2. tax_calculate_t
					queryServIdSql = sql2 + sqltemp.toString();
					
				}
			}
			
			
			List<Map<String,Object>> resulttList = sidAndABMService.getSgwABMList(queryServIdSql);
			//BALANCE_TYPE_ID  BALANCE_TYPE_NAME   REGION_ID  EFF_DATE    

			// 封装返回信息
			Map<String, Object> data = new HashMap<String, Object>();
			if(resulttList != null && !resulttList.isEmpty()) {
				List<Map<String, Object>> balanceList = new ArrayList<Map<String, Object>>();
				for(Map<String, Object> map : resulttList){
					Map<String, Object> m = new HashMap<String, Object>();
					m.put("depositTypeId", map.get("BALANCE_TYPE_ID"));
					m.put("depositTypeName", map.get("BALANCE_TYPE_NAME"));
					m.put("depositTypeClass", "");
					m.put("regoinId", map.get("REGION_ID"));
					m.put("statusCd", "");
					m.put("createStaff", "");
					m.put("updateStaff", "");
					m.put("createDate",  map.get("EFF_DATE"));
					m.put("updateDate",  map.get("EFF_DATE"));
					m.put("statusDate", map.get("EFF_DATE"));
					balanceList.add(m);
				}
				if(isbalance == 0) {
					//单条
					data.put("depositType", balanceList.get(0));
					data.put("Id", "");
					data.put("href", "");
				}else {
					//列表
					data.put("depositType", balanceList);
				}
				
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else if(resulttList != null){
				data.put("resultCode", "0");
				data.put("resultMsg", "SUCCESS");
			}else {
				data.put("resultCode", "-1");
				data.put("resultMsg", "查询失败");
			}
			Gson gson = new Gson();
			resp = gson.toJson(data);
		} catch (Exception e) {
			throw e;
		}
		return resp;
	}
	public int endProcess(CallParam callParam) {
		logger.info("callParam.getServiceResultCode()----"+callParam.getServiceResultCode());
	    if (Constants.LOG.isDebugEnabled()) {
	        Constants.LOG.debug("ForwardProcessor handleAnswer");
	    }
	    callParam.getAsynHandler().onCallResult(callParam);
	    return 0;
	}
	
	private static List<String> getMonthBetween(String minDate, String maxDate) throws ParseException {
	    ArrayList<String> result = new ArrayList<String>();
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");//格式化为年月

	    Calendar min = Calendar.getInstance();
	    Calendar max = Calendar.getInstance();

	    min.setTime(sdf.parse(minDate));
	    min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);

	    max.setTime(sdf.parse(maxDate));
	    max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);

	    Calendar curr = min;
	    while (curr.before(max)) {
	     result.add(sdf.format(curr.getTime()));
	     curr.add(Calendar.MONTH, 1);
	    }

	    return result;
	  }

	public static void main(String[] args) throws ParseException {
		String str="[\r\n" + 
				"  {\r\n" + 
				"    \"mdn\": \"18941127757\",\r\n" + 
				"    \"imei\": \"86907545320\",\r\n" + 
				"    \"messageId\": \"00000000000000000001\",\r\n" + 
				"    \"model\": \"xxx-xxx\",\r\n" + 
				"    \"5GFlag\": \"1\",\r\n" + 
				"    \"provinceId\": \"8110000\"\r\n" + 
				"  },\r\n" + 
				"  {\r\n" + 
				"    \"mdn\": \"18986137973\",\r\n" + 
				"    \"imei\": \"86907545321\",\r\n" + 
				"    \"messageId\": \"00000000000000000002\",\r\n" + 
				"    \"model\": \"xxx-xxx\",\r\n" + 
				"    \"5GFlag\": \"1\",\r\n" + 
				"    \"provinceId\": \"8110000\"\r\n" + 
				"  }\r\n" + 
				"]";
		List<JSONObject> imeiInfoList = JSONObject.parseArray(str, JSONObject.class);
		System.out.println(imeiInfoList.size());
	}
}
